home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
et
/
et3_0-a1.lha
/
et3
/
src
/
BitSet.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-05
|
1KB
|
75 lines
#ifdef __GNUG__
#pragma implementation
#endif
#include "BitSet.h"
#include "Class.h"
//---- BitSet ------------------------------------------------------------------
NewMetaImpl(BitSet,Object, (TX(m)));
int BitSet::Capacity()
{
return sizeof(int)*8;
}
u_long BitSet::Hash()
{
return m;
}
bool BitSet::IsEmpty()
{
return m==0;
}
bool BitSet::IsEqual(Object* ob)
{
return ob->IsKindOf(BitSet) && m == ((BitSet*)ob)->m;
}
OStream& BitSet::PrintOn(OStream &s)
{
Object::PrintOn(s);
return s << m SP;
}
IStream& BitSet::ReadFrom(IStream &s)
{
long mm;
Object::ReadFrom(s);
s >> mm;
m= (u_long) mm;
return s;
}
int BitSet::Size()
{
register u_long l, n;
for (l= m, n= 0; l != 0; n++)
l &= (l-1); // removes rightmost 1
return n;
}
//---- class BitSetIter ----------------------------------------------------
void BitSetIter::Reset(BitSet *s)
{
cb= s;
pos= 0;
}
int BitSetIter::operator()()
{
while (!cb->Includes(pos) && pos < cb->Capacity())
pos++;
if (pos == cb->Capacity())
return 0;
return pos++;
}